<?php

/**
 * Description of MenuList
 *
 * @author gun
 */
class CHelper_View_Helper_MenuList extends Zend_View_Helper_Abstract {
    
    public function setView(\Zend_View_Interface $view) {
        parent::setView($view);
    }
    
    public function MenuList($groupID) {
        $menuService = AppRegistry::loadService('Admin_Model_MenuService');
        $menus = $menuService->findAll($groupID);
            
        $grpID = array_values($groupID);
        $menu = '<tr><td>' . '<input id="chkall" type="checkbox" value=""/> CheckAll' . '</td></tr>';                
        
        foreach($menus as $key => $value) {
            if ('0' === $value['parentID']) {
                $menu .= '<tr><td><ul type="none">' . 
                        '<li>
                            <input type="hidden" id="hdnval" name="parent_'. $value['menuID'] .'" value="false"/>
                            <input id="chkbox_'. $key .'" class="prntchk" type="checkbox" name="parent_'. $value['menuID'] 
                                .'" value="true" ' .('1' === $value['status'] ? 'checked' : ''). '/> &nbsp;&nbsp;' . $value['name'];
                                
                $child = $menuService->getChildMenu($grpID[0], $value['menuID']);
//                echo "<pre>", print_r($child), "</pre>";
                if ($child) {
                    $menu .= '<ul type="none">';
                    foreach ($child as $k => $childItem) {
                        $menu .= '<li>
                                    <input type="hidden" id="hdnval" name="chld_'.$childItem['menuID'].'" value="false"/>
                                    <input id="chkbox_'. $key .'_'. $k .'" class="chldchk" type="checkbox" name="chld_'.$childItem['menuID'].'" value="true" ' .('1' === $childItem['status'] ? 'checked' : ''). '/> &nbsp;&nbsp;' . $childItem['name'] . '</li>';
                    }
                    
                    $menu .= '</ul></li></ul></td></tr>';
                    
                } else {
                    $menu .= '</li></ul></td></tr>';

                }
            }
        }
        
        $menu .= '<tr>
                    <td colspan="2">
                        <button id="save-btn" class="green" onclick="Web.Do({formid: \'#form_edit_acl\', param: {type: \'save\'}});"> Save </button> &nbsp; 
                        <button id="cancel-btn" onclick="Web.Do({formid: \'#form_edit_acl\', param: {type: \'cancel\'}});"> Cancel </button>
                    </td>
                </tr>';
        
        $menu .= '</form>';
        
        return $menu;
    }    
}
